package com.lxmes.business.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.lxmes.base.domain.JcIteminfo;
import com.lxmes.business.domain.CcCaigouDetail;
import com.lxmes.business.domain.CcStockinfoInfo;
import com.lxmes.business.mapper.CcStockinfoInfoMapper;
import com.lxmes.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lxmes.business.mapper.CcChukuDetailMapper;
import com.lxmes.business.domain.CcChukuDetail;
import com.lxmes.business.service.ICcChukuDetailService;

/**
 * 出库详情Service业务层处理
 * 
 * @author 王超
 * @date 2022-06-29
 */
@Service
public class CcChukuDetailServiceImpl implements ICcChukuDetailService 
{
    @Autowired
    private CcChukuDetailMapper ccChukuDetailMapper;
    @Autowired
    private CcStockinfoInfoMapper ccStockinfoInfoMapper;

    /**
     * 查询出库详情
     * 
     * @param id 出库详情主键
     * @return 出库详情
     */
    @Override
    public CcChukuDetail selectCcChukuDetailById(Long id)
    {
        return ccChukuDetailMapper.selectCcChukuDetailById(id);
    }

    @Override
    public List<CcChukuDetail> selectCcChukuDetailByDanHao(String danhao) {
        return ccChukuDetailMapper.selectCcChukuDetailByDanHao(danhao);
    }

    /**
     * 查询出库详情列表
     * 
     * @param ccChukuDetail 出库详情
     * @return 出库详情
     */
    @Override
    public List<CcChukuDetail> selectCcChukuDetailList(CcChukuDetail ccChukuDetail)
    {
        return ccChukuDetailMapper.selectCcChukuDetailList(ccChukuDetail);
    }
    /*添加出库库存的物料*/
    @Override
    public List<CcChukuDetail> addChuKuStockinfo(Long[] ids) {
        List<CcChukuDetail>  ccChukuDetailList =new ArrayList<>();
        List<CcStockinfoInfo> ccStockinfoInfoList = ccStockinfoInfoMapper.selectCcStockinfoInfoByIds(ids);
        if(ccStockinfoInfoList.size()>0){
            for (CcStockinfoInfo info :ccStockinfoInfoList) {
                CcChukuDetail ccChukuDetail=new CcChukuDetail();
                ccChukuDetail.setItemCode(info.getItemId());
                ccChukuDetail.setItemName(info.getJcItemName());
                ccChukuDetail.setClassId(info.getClassId());
                ccChukuDetail.setClassName(info.getClassName());
                ccChukuDetail.setSpec(info.getSpec());
                ccChukuDetail.setSupplyId(info.getSupplyId());
                ccChukuDetail.setSupplyName(info.getSupplyName());
                ccChukuDetail.setUnit(info.getUnit());
                ccChukuDetail.setCkNum(new BigDecimal("0") );
                ccChukuDetail.setStockNum(info.getKcNum().subtract(info.getLockNum()));
                ccChukuDetail.setStockId(info.getStockId());
                ccChukuDetail.setKuquCode(info.getKuquCode());
                ccChukuDetail.setKuquName(info.getKuquName());
                ccChukuDetail.setKuweiCode(info.getKuweiCode());
                ccChukuDetail.setStockName(info.getStockName());
                ccChukuDetail.setUnitPrice(info.getUnitPrice());
                ccChukuDetail.setLot(info.getLot());
                ccChukuDetailList.add(ccChukuDetail);
            }
        }
        return ccChukuDetailList;
    }

    /**
     * 新增出库详情
     * 
     * @param ccChukuDetail 出库详情
     * @return 结果
     */
    @Override
    public int insertCcChukuDetail(CcChukuDetail ccChukuDetail)
    {
        ccChukuDetail.setCreateTime(DateUtils.getNowDate());
        return ccChukuDetailMapper.insertCcChukuDetail(ccChukuDetail);
    }

    /**
     * 修改出库详情
     * 
     * @param ccChukuDetail 出库详情
     * @return 结果
     */
    @Override
    public int updateCcChukuDetail(CcChukuDetail ccChukuDetail)
    {
        ccChukuDetail.setUpdateTime(DateUtils.getNowDate());
        return ccChukuDetailMapper.updateCcChukuDetail(ccChukuDetail);
    }

    /**
     * 批量删除出库详情
     * 
     * @param ids 需要删除的出库详情主键
     * @return 结果
     */
    @Override
    public int deleteCcChukuDetailByIds(Long[] ids)
    {
        return ccChukuDetailMapper.deleteCcChukuDetailByIds(ids);
    }

    /**
     * 删除出库详情信息
     * 
     * @param id 出库详情主键
     * @return 结果
     */
    @Override
    public int deleteCcChukuDetailById(Long id)
    {
        return ccChukuDetailMapper.deleteCcChukuDetailById(id);
    }
}
